from web import app
from flask import request,render_template,flash,abort,url_for,redirect,session,Flask
from bson import json_util
from pymongo import MongoClient
from product.mongodb import mongodb
from web.service import reviews_service

@app.route('/data/reviews/getData',methods=['POST'])
def getReviewsData():
    page = int(request.form['page'])
    limit = int(request.form['limit'])
    conn = MongoClient(mongodb.ip, 27017)
    db = conn.pinduoduo
    goodsReviewsDB = db.goodsReviews
    data = list(goodsReviewsDB.find().skip((page - 1) * limit).limit(limit))
    count = len(list(goodsReviewsDB.find()))
    returnJson = {
        'code': 0,
        'msg': 'success',
        "count": count,
        "data": (data)
    }
    return json_util.dumps(returnJson)

#获取评价数据
@app.route('/reviews/getReviews',methods=['POST'])
def getReviews():
    reviewsService = reviews_service.reviewsService()
    return reviewsService.getData(request)